package com.stx.test.classArray;

import java.util.Scanner;

/**
 * packageName com.shuangti.test
 *
 * @author YangYi
 * @className PigSystem
 * @date 2025/8/30
 * @description TODO
 */
public class PigSystem {
    Scanner scanner = new Scanner(System.in);

    Pig[] pigs;

    public void meun() {
        boolean isExist = false;
        while (!isExist) {
            System.out.println("*****************");
            System.out.println("**欢迎使用养猪系统**");
            System.out.println("****1、添加小猪****");
            System.out.println("****2、修改重量****");
            System.out.println("****3、删除小猪****");
            System.out.println("****4、展示小猪****");
            System.out.println("****5、退出系统****");
            System.out.println("*****************");
            int choose = scanner.nextInt();
            switch (choose) {
                case 1: {
                    addPig();
                    break;
                }
                case 2: {
                    updatePigWeight();
                    break;
                }
                case 3: {
                    deletePigByNUm();
                    break;
                }
                case 4: {
                    showPigs();
                    break;
                }
                case 5: {
                    System.out.println("退出系统");
                    System.exit(0);
                    break;
                }
                default: {
                    System.out.println("输入有误！！！");
                }
            }
        }
    }

    /**
     * 新增小猪
     */
    public void addPig() {
        Pig addPig = new Pig();
        System.out.println("请输入小猪姓名：");
        String name = scanner.next();
        addPig.setName(name);
        System.out.println("请输入小猪编号：");
        int num = scanner.nextInt();
        addPig.setNum(num);
        System.out.println("请输入小猪体重：");
        double weigth = scanner.nextDouble();
        addPig.setWeigth(weigth);
        System.out.println("请输入小猪年龄：");
        double age = scanner.nextDouble();
        addPig.setAge(age);
        addPig.setHealth(true);
        for (int i = 0; i < pigs.length; i++) {
            if (pigs[i] == null) {
                pigs[i] = addPig;
                System.out.println("添加成功");
                break;
            }
        }
        System.out.println("退出添加");
    }
    /**
     * 显示所有小猪
     * 需求：根据输入的小猪编号进行显示，
     * 输入某个字符时全部展示，没有对应编号则提示错误
     */
    public void showPigs() {
        for (int i = 0; i < pigs.length; i++) {
            if (pigs[i] != null) {
                System.out.println("小猪编号：" + pigs[i].num +
                        "，小猪姓名：" + pigs[i].name + "，小猪体重：" +
                        pigs[i].weigth + "，小猪年龄：" + pigs[i].age +
                        "健康状态："+pigs[i].health);
            }
        }
    }
    /**
     * 更新小猪重量
     */
    public void updatePigWeight() {
        System.out.println("请输入小猪编号：");
        int num = scanner.nextInt();
        for (int i = 0; i < pigs.length; i++) {
            if (num == pigs[i].num) {
                System.out.println("请更新小猪的重量：");
                double weight = scanner.nextDouble();
                pigs[i].weigth = weight;
                System.out.println("小猪重量更新成功");
                return;
            }
        }
        System.out.println("没有找到该小猪，请重写输入");
    }

    /**
     * 删除小猪
     */
    public void deletePigByNUm() {
        System.out.println("请输入需要删除的小猪编号：");
        int num = scanner.nextInt();
        for (int i = 0; i < pigs.length; i++) {
            if (num == pigs[i].num) {
                pigs[i] = null;
                System.out.println("小猪删除成功");
                return;
            }
        }
        System.out.println("没有找到该小猪，请重写输入");
    }
    public Pig[] getPigs() {
        return pigs;
    }

    public void setPigs(Pig[] pigs) {
        this.pigs = pigs;
    }
}
